/**
 * 班级管理初始化
 */
var StatReport = {
    id: "statReportTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
StatReport.initColumn = function () {
    return [
            {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '学校代号', field: 'schoolCode', visible: true, align: 'center', valign: 'middle',footerFormatter: function (value) {
                return '合计';}},
            {title: '学校名称', field: 'schoolName', visible: true, align: 'center', valign: 'middle'},
            {title: '所在班级', field: 'className', visible: true, align: 'center', valign: 'middle',  footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                    count++;
                }
                return count!=0?count:0+"";}},
            {title: '报名人数', field: 'examineeNum', visible: true, align: 'center', valign: 'middle',  footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                	 count +=parseInt(value[i].examineeNum);
                }
                return count!=0?count:0+"";}},
            {title: '未填报志愿人数', field: 'nowriteNum', visible: true, align: 'center', valign: 'middle',  footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                	 count += parseInt(value[i].nowriteNum);
                }
                return count!=0?count:0+"";}},
            {title: '已填报志愿人数', field: 'thenwriteNum', visible: true, align: 'center', valign: 'middle',  footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                	 count += parseInt(value[i].thenwriteNum);
                }
                return count!=0?count:0+"";}},
            {title: '已放弃志愿人数', field: 'abandonedNum', visible: true, align: 'center', valign: 'middle',  footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                	 count += parseInt(value[i].abandonedNum);
                }
                return count!=0?count:0+"";}},
            {title: '未确认志愿人数', field: 'noconfirmNum', visible: true, align: 'center', valign: 'middle',  footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                	 count += parseInt(value[i].noconfirmNum);
                }
                return count!=0?count:0+"";}},
            {title: '已确认志愿人数', field: 'thenconfirmNum', visible: true, align: 'center', valign: 'middle',  footerFormatter: function (value) {
                var count = 0;
                for (var i in value) {
                	 count += parseInt(value[i].thenconfirmNum);
                }
                return count!=0?count:0+"";}}
    ];
};

/**
 * 上报
 */
StatReport.report=function(){
	if($('#' + StatReport.id).find("tr").eq(1).find("td").length<=1){
		 Feng.error("没有匹配的记录,不能上报！");
	}else{
		 var ajax = new $ax(Feng.ctxPath + "/seniorWish/report", function (data) {
	         Feng.success("上报成功！");
	         StatReport.table.refresh();
	     }, function (data) {
	    	 Feng.error(data.responseJSON.message + "！");
	     });
	     ajax.start();
	}
}

/**
 * 获取shoolId
 */
StatReport.getSchoolId=function(schoolSelectId){
	return {
		schoolId:$("#"+schoolSelectId).select2("val")
	}
}

$('#seniorSchoolId').on('select2:select', function (e) {
	$("#seniorClassId").val("").trigger("change");
});

StatReport.resetSearch = function () {
    $("#seniorSchoolId").val("").trigger("change");
    $("#seniorClassId").val("").trigger("change");
    StatReport.search();
}

/**
 * 查询班级列表
 */
StatReport.search = function () {
    var queryData = {};
    queryData['seniorSchoolId'] = $("#seniorSchoolId").val();
    queryData['seniorClassId'] = $("#seniorClassId").val();
    StatReport.table.refresh({query: queryData});
};

$(function () {
    var defaultColumns = StatReport.initColumn();
    var table = new BSTable(StatReport.id, "/seniorWish/statReportList", defaultColumns);
    table.setIsShowSelect(false);
    table.setShowFooter(true);
    StatReport.table = table.init();
    $('#' + StatReport.id).on('load-success.bs.table',function(data){
    	if($('#' + StatReport.id).find("tr").eq(1).find("td").length<=1){
    		$(".fixed-table-footer").hide();
    	}
    });
});
